<!-- start-->
<div class=" print">


    <!-- 表单 -->   
    <section class="panel-body" >
            <form role="form" class="form-edit">

                <div class="form-group col-sm-6">
                    <span>编号</span>
                    <input type="text" class="form-control" placeholder="编号" name="sn" v-model="param.sn" disabled="disabled">
                </div>

                <div class="form-group col-sm-6">
                    <span>入库类型</span>
                    <select name="supplier" class="form-control" v-model="param.type" disabled="disabled" >
                        <option value="1" >采购入库</option>
                        <option value="2" >手动入库</option>
                    </select>
                </div>

                <div class="form-group col-sm-6" v-show="param.type == 1 ">
                    <span>关联订单</span>
                    <select name="purchase" class="form-control comboSelect purchase" v-model="param.purchase" disabled="disabled">
                        {volist name="list" id="vo"}
                            <option value="{$vo.id}" >{$vo.sn}-{$vo.author}</option>
                        {/volist}
                    </select>
                </div>

                <div class="form-group col-sm-6">
                    <span>入库人</span>
                    <input type="text" class="form-control" placeholder="入库人" name="author" v-model="param.author" disabled="disabled">
                </div>

                <div class="form-group col-sm-6">
                    <span>供应商</span>
                    <select name="supplier" class="form-control comboSelect" v-model="param.supplier" disabled="disabled">
                        {volist name="supplier" id="vo"}
                            <option value="{$vo.id}" >{$vo.title}</option>
                        {/volist}
                    </select>
                </div>                

                <div class="form-group col-sm-6">
                    <span>入库日期</span>
                    <input type="text" class="form-control" placeholder="入库日期" name="in_date" id="in_date" v-model="param.in_date" disabled="disabled">
                </div>

                {include file="common/depot-table" /}

                <div class="form-group col-sm-12 no-print">
                    <button type="button" class="btn btn-sm btn btn-primary" @click="print">  打印 </button>
                </div>

            </form>
    </section>    



</div>
<!-- end -->

<script src="/static/admin/js/jQuery.print.min.js"></script>
<script>

var list = [];
var layer_index = 0;

// seajs
seajs.use(['vendor/comboSelect/jquery.combo.select','vendor/laydate/laydate'],function() {

    var data = {
        name: '名称',
        model: '型号',
        spec: '规格',
        color: '颜色',
        num: '数量',
        unit: '单位',
        price: '单价',
        count: '合计',
    };

    var edit = new Vue({
        el: '.print',
        data: {
            data:data,
            count: '{$row.count}',
            list: list,
            param:{
                sn:"{$row.sn}",
                author:"{$row.author}",
                in_date: "{$row.in_date}",
                supplier: "{$row.supplier}",
                data: this.list,
                count: this.count,
                id:'{$row.id}',
                // purchase: this.purchase,
                purchase: '{$row.purchase}',
                type: parseInt('{$row.type}')
            }
        },
        mounted: function (){   
            this.getList();
        },
        methods: {
            print: function () {
                $(".print").print({
                    globalStyles : true,
                    addGlobalStyles : true,
                    stylesheet : null,
                    rejectWindow : true,
                    noPrintSelector : ".no-print",
                    iframe : true,
                    append : null,
                    prepend : null
                });
            },
            getList:function(){
                var _this = this;
                $.getJSON("{:url('purchase/getList')}?model=indepot&id={$row.id}", function(data){
                    list = data;
                    _this.list = data;
                    _this.SumCount();
                });
            },
            addLine: function(){

                if( this.param.type == 2 ){
                    $.get("{:url('product/select')}", function(data) {
                        layer_index = layer.open({
                            type: 1,
                        　　title: "选择产品",
                        　　shadeClose: true,
                        　　shade: 0.4,
                            anim: 5,
                            area: ['150%','500px'],
                        　　content: data
                        });
                    });
                }

            },
            delLine:function(index){
                this.param.type == 2 && this.list.splice(index,1);
            },
            changeSum:function(index){
                this.list[index].count = this.list[index].num * this.list[index].price;
                this.SumCount();
            },
            SumCount:function(){
                this.count = 0;
                for(var index in this.list) {  
                    this.count += parseFloat( this.list[index].count );
                };  
            }

        }


    });


// $('.comboSelect').change(function(){
//     var name = $(this).attr('name');
//     var val = $(this).val();
//     console.log(val);
//     create.param[name] = val;
//     create.getList();
// });

    $('.purchase').change(function(){
        var name = $(this).attr('name');
        var val = $(this).val();
        // console.log(val);
        edit.param[name] = val;
        edit.getList();
    });




});


</script>